home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HTBasic 9.3
/
HTBasic 9.3.iso
/
83win
/
data1.cab
/
Basic_Plus_Examples
/
SLOTS
< prev
next >
Wrap
Text File
|
2001-03-02
|
6KB
|
153 lines
10 ! ************************************************************************
20 ! Example: Slot Machine
30 !
40 ! This example program simulates a slot machine.
50 ! It illustrates the use of STRING widgets with different fonts, and
60 ! shows how attribute arrays can be used. The PUSHBUTTON object is used
70 ! to initiate an action. The PRINTER widget is used to display information
80 ! to the user.
90 !
100 ! The arrays Attr_n$ and Attr are used to program six numeric attributes
110 ! at once. The arrays Attr_s$ and Attr_sv$ are used to program two string
120 ! attributes.
130 !
140 ! ************************************************************************
150 !
160 DIM Attr_n$(5)[11],Attr_s$(1)[10],Attr(5),Attr_sv$(1)[10],Poss$(6)[6]
170 Attr_n$(0)="X"
180 Attr_n$(1)="Y"
190 Attr_n$(2)="WIDTH"
200 Attr_n$(3)="HEIGHT"
210 Attr_n$(4)="RESIZABLE"
220 Attr_n$(5)="MAXIMIZABLE"
230 Attr(0)=100 ! x position
240 Attr(1)=20 ! y position
250 Attr(2)=120 ! width
260 Attr(3)=50 ! height
270 Attr(4)=0 ! resizable
280 Attr(5)=0 ! maximizable
290 Attr_s$(0)="FONT"
300 Attr_s$(1)="TITLE"
310 Attr_sv$(0)="20 BY 30"
320 Attr_sv$(1)="" ! Makes the title area disappear
330 !
340 ASSIGN @Slot1 TO WIDGET "STRING"
350 CONTROL @Slot1;SET (Attr_n$(*):Attr(*),Attr_s$(*):Attr_sv$(*))
360 CONTROL @Slot1;SET ("BACKGROUND":1,"PEN":2)
370 !
380 ! Position the second STRING widget to the right of the first
390 !
400 Attr(0)=Attr(0)+Attr(2)
410 ASSIGN @Slot2 TO WIDGET "STRING"
420 CONTROL @Slot2;SET (Attr_n$(*):Attr(*),Attr_s$(*):Attr_sv$(*))
430 CONTROL @Slot2;SET ("BACKGROUND":1,"PEN":2)
440 !
450 ! Position the third STRING widget to the right of the second
460 !
470 Attr(0)=Attr(0)+Attr(2)
480 ASSIGN @Slot3 TO WIDGET "STRING"
490 CONTROL @Slot3;SET (Attr_n$(*):Attr(*),Attr_s$(*):Attr_sv$(*))
500 CONTROL @Slot3;SET ("BACKGROUND":1,"PEN":2)
510 !
520 ! Create a button to quit the game
530 !
540 ASSIGN @Quit TO WIDGET "PUSHBUTTON"
550 CONTROL @Quit;SET ("X":150,"Y":100,"RESIZABLE":0,"MAXIMIZABLE":0)
560 CONTROL @Quit;SET ("TITLE":"","FONT":"20 BY 30","LABEL":" QUIT ")
570 ON EVENT @Quit,"ACTIVATED" GOTO Finis
580 !
590 ! Create a button to simulate pulling the lever
600 !
610 ASSIGN @Pull TO WIDGET "PUSHBUTTON"
620 CONTROL @Pull;SET ("X":300,"Y":100,"RESIZABLE":0,"MAXIMIZABLE":0)
630 CONTROL @Pull;SET ("TITLE":"","FONT":"20 BY 30","LABEL":" PULL ")
640 !
650 ! The value remaining in the bankroll is displayed in another string
660 ! widget which retains its title area
670 !
680 Bankroll=100
690 ASSIGN @Bank TO WIDGET "STRING"
700 CONTROL @Bank;SET ("X":300,"Y":175,"MAXIMIZABLE":0)
710 CONTROL @Bank;SET ("TITLE":" BANKROLL","WIDTH":150)
720 CONTROL @Bank;SET ("VALUE":" $"&VAL$(Bankroll))
730 !
740 ! Explain the costs and payoffs in a PRINTER widget
750 !
760 ASSIGN @Info TO WIDGET "PRINTER"
770 CONTROL @Info;SET ("X":100,"Y":175,"ROWS":5,"COLUMNS":21)
780 CONTROL @Info;SET ("RESIZABLE":0,"MAXIMIZABLE":0,"TITLE":" ODDS")
790 CONTROL @Info;SET ("TEXT":"Each pull costs $5")
800 CONTROL @Info;SET ("APPEND TEXT":"3 bars pays $100")
810 CONTROL @Info;SET ("APPEND TEXT":"Any 2 bars pays $20")
820 CONTROL @Info;SET ("APPEND TEXT":"Any 2 7s pays $10")
830 CONTROL @Info;SET ("APPEND TEXT":"Any pair pays $5")
840 !
850 ! This array contains the possible values on the wheels
860 !
870 Poss$(0)=" BAR"
880 Poss$(1)=" BELL"
890 Poss$(2)="APPLE"
900 Poss$(3)="CHERRY"
910 Poss$(4)=" PLUM"
920 Poss$(5)=" 7"
930 !
940 ! When the pull button is clicked, get some new values
950 !
960 ON EVENT @Pull,"ACTIVATED",1 GOSUB Pulled
970 !
980 LOOP
990 WAIT FOR EVENT
1000 END LOOP
1010 Pulled:!
1020 Bankroll=Bankroll-5
1030 CONTROL @Bank;SET ("VALUE":" $"&VAL$(Bankroll))
1040 FOR I=1 TO 8+RND*8
1050 Val1=INT(RND*6)
1060 CONTROL @Slot1;SET ("VALUE":Poss$(Val1))
1070 WAIT .05
1080 Val2=INT(RND*6)
1090 CONTROL @Slot2;SET ("VALUE":Poss$(Val2))
1100 WAIT .05
1110 Val3=INT(RND*6)
1120 CONTROL @Slot3;SET ("VALUE":Poss$(Val3))
1130 WAIT .05
1140 NEXT I
1150 !
1160 ! Assume no payoff
1170 !
1180 Win=0
1190 !
1200 ! Check for a pair
1210 !
1220 IF Val1=Val2 OR Val1=Val3 OR Val2=Val3 THEN Win=5
1230 !
1240 ! Check for a pair of 7s
1250 !
1260 IF (Val1=5 AND (Val1=Val2 OR Val1=Val3)) OR (Val2=5 AND (Val2=Val3)) THEN Win=10
1270 !
1280 ! Check for a pair of bars
1290 !
1300 IF (Val1=0 AND (Val1=Val2 OR Val1=Val3)) OR (Val2=0 AND (Val2=Val3)) THEN Win=20
1310 !
1320 ! Check for three bars
1330 !
1340 IF Val1=0 AND Val2=0 AND Val3=0 THEN Win=100
1350 !
1360 ! Declare any winnings
1370 !
1380 IF Win>0 THEN DIALOG "INFORMATION","You WON $"&VAL$(Win);TIMEOUT 10
1390 Bankroll=Bankroll+Win
1400 CONTROL @Bank;SET ("VALUE":" $"&VAL$(Bankroll))
1410 IF Bankroll<=0 THEN STOP
1420 RETURN
1430 !
1440 Finis:!
1450 ASSIGN @Slot1 TO *! Delete STRING widget
1460 ASSIGN @Slot2 TO *! Delete STRING widget
1470 ASSIGN @Slot3 TO *! Delete STRING widget
1480 ASSIGN @Quit TO * ! Delete PUSHBUTTON widget
1490 ASSIGN @Pull TO * ! Delete PUSHBUTTON widget
1500 ASSIGN @Bank TO * ! Delete STRING widget
1510 ASSIGN @Info TO * ! Delete PRINTER widget
1520 END